package com.androdro.bluenote.birdland1521;
/**
 * A Night at Birdland with Art Blakey Quintet
 * WeeDot.java
 *
 * @author Hiroaki Sakuma <sakuma@androdro.com>
 * @version $Id$
 *
 * Copyright (C) androdro lab. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of the nor the names of its contributors may be used to
 *   endorse or promote products derived from this software without specific
 *   prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 *
 */

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.Toast;

public abstract class WeeDot
	implements
		Birdland1521 {

	/**
   * This class is droid robot.
   *
   */

	private SplitKick root;

	private Resources r;
	private Bitmap bitmapDroid, resizedBitmapDroid;
	private Paint p;

	private float x, y;
	private double scale = 1.0;
	private double degrees = 0.0;
	private float alpha = 255.0f;


	public WeeDot(SplitKick root, Bitmap bitmapDroid) {

		this.root = root;
		this.r = this.root.getResources();

		try {

			this.bitmapDroid = bitmapDroid;
			this.p = new Paint();
			setAlpha(this.alpha);

		} catch (Exception e) {
			e.printStackTrace();
			Toast.makeText(this.root, e.toString() + "on " + getClass().toString() + " " + e.getStackTrace()[0].getMethodName(), Toast.LENGTH_LONG).show();
		}

	}


	public Bitmap getBitmap() {

		Matrix matrix;

		matrix = new Matrix();
		matrix.preTranslate(this.bitmapDroid.getWidth() * -0.5f, 0);
		matrix.postRotate((float)this.degrees);
		matrix.postScale((float)scale, (float)scale);
		matrix.postTranslate(this.bitmapDroid.getWidth() * 0.5f, 0);

		this.resizedBitmapDroid = Bitmap.createBitmap(this.bitmapDroid, 0, 0, this.bitmapDroid.getWidth(), this.bitmapDroid.getHeight(), matrix, true);
		return this.resizedBitmapDroid;

	}


	public WeeDot setXY(float x, float y) {
		this.x = x;
		this.y = y;
		return this;
	}


	public WeeDot setXY(MotionEvent event) {
		this.x = event.getX();
		this.y = event.getY();
		return this;
	}


	public float getScale() {
		return (float)this.scale;
	}

	public WeeDot setScale(float scale) {
		return setScale((double)scale);
	}

	public WeeDot setScale(double scale) {
		this.scale = scale;
		return this;
	}


	public double getDegrees() {
		return this.degrees;
	}

	public WeeDot setDegrees(double degrees) {
		this.degrees = degrees;
		return this;
	}

	public WeeDot setDegrees(float degrees) {
		return setDegrees((double)degrees);
	}

	public WeeDot setDegrees(int degrees) {
		return setDegrees((double)degrees);
	}


	public float getX() {
		return this.x;
	}


	public float getY() {
		return this.y;
	}


	public float setX(float x) {
		this.x = x;
		return this.x;
	}


	public float setY(float y) {
		this.y = y;
		return this.y;
	}


	public float getCenterX() {
		return this.x - (this.resizedBitmapDroid.getWidth() * (float)this.scale / 2.0f);
	}


	public float getCenterY() {
		return this.y - (this.resizedBitmapDroid.getHeight() * (float)this.scale / 2.0f);
	}


	public float getXbyCenterX(float x) {
		return x - (this.resizedBitmapDroid.getWidth() * (float)this.scale / 2.0f);
	}


	public float getYbyCenterY(float y) {
		return y - (this.resizedBitmapDroid.getHeight() * (float)this.scale / 2.0f);
	}


	public float getOriginalCenterX() {
		return this.x - (this.bitmapDroid.getWidth() * (float)this.scale / 2.0f);
	}


	public float getOriginalCenterY() {
		return this.y - (this.bitmapDroid.getHeight() * (float)this.scale / 2.0f);
	}


	public float getWidth() {
		return this.resizedBitmapDroid.getWidth();
	}


	public float getHeight() {
		return this.resizedBitmapDroid.getHeight();
	}


	public float getAlpha() {
		return this.alpha;
	}


	public WeeDot setAlpha(int alpha) {
		return setAlpha((float)alpha);
	}

	public WeeDot setAlpha(long alpha) {
		return setAlpha((float)alpha);
	}

	public WeeDot setAlpha(float alpha) {
		this.alpha = alpha;
		this.p.setAlpha((int)this.alpha);
		return this;
	}


	public Paint getPaint() {
		return this.p;
	}


	public boolean isStackable(float nx, float ny) {
		if (nx > this.x && nx < this.x + getWidth()) {
			if (ny < this.y && ny < this.y + getHeight()) {
				return true;
			}
		}
		return false;
	}


}
